﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Othello_Game
{
    public partial class SettingsPage : Form
    {
        public SettingsPage(Color p1,Color p2,Color back,Color board)
        {            
            InitializeComponent();
            this.p1alpha = p1.A;
            this.p1alphatb.Value = p1alpha;

            this.p1blue = p1.B;
            this.p1bluetb.Value = p1blue;

            this.p1red = p1.R;
            this.p1redtb.Value = p1red;

            this.p1green = p1.G;
            this.p1greentb.Value = p1green;

            this.p2alpha = p2.A;
            this.p2alphatb.Value = p2alpha;

            this.p2blue = p2.B;
            this.p2bluetb.Value = p2blue;

            this.p2red = p2.R;
            this.p2redtb.Value = p2red;

            this.p2green = p2.G;
            this.p2greentb.Value = p2green;

            this.boardblue = board.B;
            this.boardbluetb.Value = boardblue;

            this.boardred = board.R;
            this.boardredtb.Value = boardred;

            this.boardgreen = board.G;
            this.boardgreentb.Value = boardgreen;

            this.backblue = back.B;
            this.backbluetb.Value = backblue;

            this.backred = back.R;
            this.backredtb.Value = backred;

            this.backgreen = back.G;
            this.backgreentb.Value = backgreen;

            adjustBackColor();
            adjustBoardColor();
            adjustP1Color();
            adjustP2Color();

        }

        public int p1red, p1green, p1blue, p1alpha, p2red, p2green, p2blue, p2alpha, backred, backgreen, backblue, boardred, boardgreen, boardblue;

        private void adjustP1Color()
        {
            this.p1ColorPlate.BackColor = Color.FromArgb(p1red, p1green, p1blue);
            this.p1greentb.BackColor = Color.FromArgb(p1red, p1green, p1blue);
            this.p1redtb.BackColor = Color.FromArgb(p1red, p1green, p1blue);
            this.p1bluetb.BackColor = Color.FromArgb(p1red, p1green, p1blue);
            this.p1alphatb.BackColor = Color.FromArgb(p1red, p1green, p1blue);
            this.p1ColorPlate.Refresh();
            this.p1redtb.Refresh();
            this.p1greentb.Refresh();
            this.p1bluetb.Refresh();
            this.p1alphatb.Refresh();
        }

        private void adjustP2Color()
        {
            this.p2ColorPlate.BackColor = Color.FromArgb(p2red, p2green, p2blue);
            this.p2greentb.BackColor = Color.FromArgb(p2red, p2green, p2blue);
            this.p2redtb.BackColor = Color.FromArgb(p2red, p2green, p2blue);
            this.p2bluetb.BackColor = Color.FromArgb(p2red, p2green, p2blue);
            this.p2alphatb.BackColor = Color.FromArgb(p2red, p2green, p2blue);
            this.p2ColorPlate.Refresh();
            this.p2redtb.Refresh();
            this.p2greentb.Refresh();
            this.p2bluetb.Refresh();
            this.p2alphatb.Refresh();
        }

        private void adjustBackColor()
        {
            this.backColorPlate.BackColor = Color.FromArgb(backred, backgreen, backblue);
            this.backgreentb.BackColor = Color.FromArgb(backred, backgreen, backblue);
            this.backredtb.BackColor = Color.FromArgb(backred, backgreen, backblue);
            this.backbluetb.BackColor = Color.FromArgb(backred, backgreen, backblue);
            this.backColorPlate.Refresh();
            this.backredtb.Refresh();
            this.backgreentb.Refresh();
            this.backbluetb.Refresh();
        }

        private void adjustBoardColor()
        {
            this.boardColorPlate.BackColor = Color.FromArgb(boardred, boardgreen, boardblue);
            this.boardgreentb.BackColor = Color.FromArgb(boardred, boardgreen, boardblue);
            this.boardredtb.BackColor = Color.FromArgb(boardred, boardgreen, boardblue);
            this.boardbluetb.BackColor = Color.FromArgb(boardred, boardgreen, boardblue);
            this.boardColorPlate.Refresh();
            this.boardredtb.Refresh();
            this.boardgreentb.Refresh();
            this.boardbluetb.Refresh();
        }
        
        private void p1redtb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.p1red = TB.Value;
            adjustP1Color();
        }

        private void p1greentb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.p1green = TB.Value;
            adjustP1Color();
        }

        private void p1bluetb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.p1blue = TB.Value;
            adjustP1Color();
        }

        private void p1alphatb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.p1alpha = TB.Value;
            adjustP1Color();
        }

        private void p2redtb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.p2red = TB.Value;
            adjustP2Color();
        }

        private void p2greentb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.p2green = TB.Value;
            adjustP2Color();
        }

        private void p2bluetb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.p2blue = TB.Value;
            adjustP2Color();
        }

        private void p2alphatb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.p2alpha = TB.Value;
            adjustP2Color();
        }

        private void boardredtb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.boardred = TB.Value;
            adjustBoardColor();
        }

        private void boardgreentb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.boardgreen = TB.Value;
            adjustBoardColor();
        }

        private void boardbluetb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.boardblue = TB.Value;
            adjustBoardColor();
        }

        private void backredtb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.backred = TB.Value;
            adjustBackColor();
        }

        private void backgreentb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.backgreen = TB.Value;
            adjustBackColor();
        }

        private void backbluetb_Scroll(object sender, EventArgs e)
        {
            TrackBar TB = (TrackBar)sender;
            this.backblue = TB.Value;
            adjustBackColor();
        }

        private void MiniMaxRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (this.MiniMaxRadioButton.Checked) MainScreen.UseMiniMax = true;
        }

        private void NoMiniMaxRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (this.NoMiniMaxRadioButton.Checked) MainScreen.UseMiniMax = false;
        }

        private void SettingsPage_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

    }
}
